package lib.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JProgressBar;
import javax.swing.JTabbedPane;
import javax.swing.plaf.basic.BasicTabbedPaneUI;

import org.swixml.SwingEngine;

public class GuiMenu {
	/**
	 * Class which represents the menu bar 
	 */
	
	public static  JProgressBar progressBar;
	private List<JButton> menuButtons = new ArrayList<JButton>();
	private JTabbedPane tabbedPane;
	
	public GuiMenu(SwingEngine engine){
		
		menuButtons.add((JButton)engine.find("btn_profile"));
		menuButtons.add((JButton)engine.find("btn_friends"));
		menuButtons.add((JButton)engine.find("btn_search"));
		menuButtons.add((JButton)engine.find("btn_settings"));

		progressBar = (JProgressBar)engine.find("progressBar");
		this.tabbedPane = (JTabbedPane)engine.find("tabbedPane");

		init();
		initActionListener();
	}
	

	void init(){
		tabbedPane.setUI(new BasicTabbedPaneUI() {
	        protected int calculateTabAreaHeight(int tabPlacement, int horizRunCount, int maxTabHeight) {  
	        	return 0; 
	        }
	    });
	}
	

	void initActionListener(){
		
		ActionListener listener = new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				if(Integer.parseInt(e.getActionCommand()) < menuButtons.size()){
					tabbedPane.setSelectedIndex(Integer.parseInt(e.getActionCommand()));
				}
			}
		};
		
		for(JButton btn:menuButtons){
			
			btn.addActionListener(listener);
		}
	}
}